package cn.im.qywx.wx.component;

import cn.im.qywx.model.ImWxUserInfo;
import cn.im.qywx.wx.util.WriteWeiXinMsgXml;

/**
 * @Description: 功能（原件）
 */
public abstract class Component {

	/**
	 * 执行消息处理
	 *
	 * @param userInfo
	 */
	public abstract void execute(ImWxUserInfo userInfo);

	/**
	 * 设置参数
	 */
	protected void setParams(ImWxUserInfo userInfo, ComponentType ct, String content, WriteWeiXinMsgXml writeWeiXinMsgXml) {

		// 设置消息处理类型------------------------
		userInfo.getQueueInfo().setcTpye(ct);

		// 设置回复内容--------------------------
		userInfo.getQueueInfo().getWxXml().setContent(content);

		// 设置回复的内容Xml-----------------------
		writeWeiXinMsgXml.writeXml(userInfo.getQueueInfo().getWxXml());

		writeWeiXinMsgXml = null;
		content = null;

	}


	/**
	 * 组件（原件）选择器
	 *
	 * @param ct
	 * @return
	 */
	public static Component componentSelector(ComponentType ct) {

		Component com = null;

		try {
			com = ct.getComponent().newInstance();

		} catch (InstantiationException e) {
			e.printStackTrace();

		} catch (IllegalAccessException e) {
			e.printStackTrace();

		} finally {
			/*if (null == com) {
				com = new MainMenuCom();
			}*/
		}

		return com;
	}

}
